<?php
	class Chou_Creme_Model extends CI_Model {
		function __construct()
		{
			parent::__construct();	
		}
		
		function lists($p=1,$limit=50)
		{
			//if($this->session->userdata('admin_logged_in') == TRUE){
				$start = ($p-1)*50;
				$this->db->where('cc_active ', 1); 
				$this->db->order_by("cc_en", "asc");
				$this->db->limit($limit , $start);
				$this->db->from('chou_creme');
				$query = $this->db->get();
				return $query->result();
			//}
		}
		
		function add($input)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['cc_en'] != null) {
					$data = array(
						'cc_en' => $input['cc_en'] ,
						'cc_jp' => $input['cc_jp']
					); 
					$this->db->insert('chou_creme', $data);
					return $this->db->insert_id();
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
		
		function update($input)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['id'] != null) {
					$data = array(
						'cc_en' => $input['cc_en'] ,
						'cc_jp' => $input['cc_jp']
					);
					$this->db->where('cc_id', $input['id']);
					//$this->db->update('chou_creme', $data);
					return $this->db->update('chou_creme', $data);
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
		
		function update_img($input)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['id'] != null) {
					$data = array(
						'cc_img' => $input['img'] ,
					);
					$this->db->where('cc_id', $input['id']);
					$this->db->update('chou_creme', $data);
					return $this->db->affected_rows();
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
		
		function get_img($input)
		{
			//if($this->session->userdata('admin_logged_in') == TRUE){
				if($input['id'] != null) {
					$this->db->select('cc_img');
					$this->db->where('cc_id', $input['id']);
					$this->db->from('chou_creme');
					$query2 = $this->db->get();
					return $query2->row();
				}else{
					return 0;
				}
			//}else{
			//	return 0;
			//}
		}
		
		function delete($id)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				$this->db->where('cc_id', $id); 
				return $this->db->delete('chou_creme');
			}
		}
		
		function change_status($id)
		{
			if($this->session->userdata('admin_logged_in') == TRUE){
				$data = array(
					'n_active' => 'ABS(n_active-1)'
				);
				$this->db->where('n_id', $n_id);
				$this->db->update('news', $data);
			}
		}
		
		function get_info($id)
		{
			//if($this->session->userdata('admin_logged_in') == TRUE){
				$this->db->where('cc_id', $id);
				$this->db->from('chou_creme');
				$query = $this->db->get();
				return $query->result();
			//}
		}
	}


/* End of file chou_creme_model.php */
/* Location: ./application/models/admin/chou_creme_model.php */